package com.publicstaticdroid.g2l_interpreter_connect;

import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.util.Log;

public class SMSSender {
	
	private SmsManager manager;
	private String destPhNum;

	public SMSSender(String destPhNum) {
		manager = SmsManager.getDefault();
		if(PhoneNumberUtils.isWellFormedSmsAddress(destPhNum)){
			this.destPhNum = destPhNum;
		}
	}
	public void sendSMS(String content) {
		Log.e("G2L", "Sending |" + content + "| to " + destPhNum);
		if(destPhNum != null){
			manager.sendTextMessage(destPhNum, null, content, null, null);
		}
		else{
			Log.e("G2L", "Invalid Phone Number");
		}
	}
	public void sendAccept(int requestID, long receiveTime, long responseTime) {
		sendSMS("accept " + requestID + " " + receiveTime + " " + responseTime);
	}
	public void sendReject(int requestID, long receiveTime, long responseTime) {
		sendSMS("reject " + requestID + " " + receiveTime + " " + responseTime);
	}
	//TODO: Reverse callStart and callEnd
	//Solvable by using < comparison on server
	public void sendFinished(int requestID, long callDuration, long callStart, long callEnd) {
		sendSMS("finished " + requestID + " " + callDuration + " " + callEnd + " " + callStart);
	}
}